package com.itheima.service.Impl;

import com.itheima.common.entity.PageResult;
import com.itheima.mapper.OrderMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public PageResult findPageByCode(Pageable pageable, String queryString) {
        int pageNum = pageable.getPageNumber();
        int pageSize = pageable.getPageSize();
        int offset = (pageNum - 1) * pageSize;
        List<Order> rows = orderMapper.findByCode(queryString, offset, pageSize);
        long total = orderMapper.countByCode(queryString);
        return new PageResult(total, rows);
    }
    @Override
    public PageResult findPageByName(Pageable pageable, String queryString) {
        int pageNum = pageable.getPageNumber();
        int pageSize = pageable.getPageSize();
        int offset = (pageNum - 1) * pageSize;
        List<Order> rows = orderMapper.findByName(queryString, offset, pageSize);
        long total = orderMapper.countByName(queryString);
        return new PageResult(total, rows);
    }
    @Override
    public PageResult findPageDefault(Pageable pageable) {
        int pageNum = pageable.getPageNumber();
        int pageSize = pageable.getPageSize();
        int offset = (pageNum - 1) * pageSize;
        List<Order> rows = orderMapper.findPage(offset, pageSize);
        long total = orderMapper.count();
        return new PageResult(total, rows);
    }
    @Override
    public boolean update(Order order) {
        return orderMapper.update(order);
    }
    @Override
    public Order findById(Integer id) {
        return orderMapper.findById(id);
    }



}
